package com.taoxi.good.controller;

import com.taoxi.common.annotation.Log;
import com.taoxi.common.core.controller.BaseController;
import com.taoxi.common.core.domain.AjaxResult;
import com.taoxi.common.core.page.TableDataInfo;
import com.taoxi.common.enums.BusinessType;
import com.taoxi.common.utils.poi.ExcelUtil;
import com.taoxi.good.domain.GoodSize;
import com.taoxi.good.service.IGoodSizeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 尺码管理Controller
 *
 * @author ruoyi
 * @date 2024-10-22
 */
@Api(tags = "尺码管理Controller")
@RestController
@RequestMapping("/good/size")
public class GoodSizeController extends BaseController {
    @Autowired
    private IGoodSizeService goodSizeService;

    /**
     * 查询尺码管理列表
     */
    @ApiOperation("查询尺码管理列表")
    @PreAuthorize("@ss.hasPermi('good:size:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodSize goodSize) {
        startPage();
        List<GoodSize> list = goodSizeService.selectGoodSizeList(goodSize);
        return getDataTable(list);
    }

    /**
     * 导出尺码管理列表
     */
    @ApiOperation("导出尺码管理列表")
    @PreAuthorize("@ss.hasPermi('good:size:export')")
    @Log(title = "尺码管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodSize goodSize) {
        List<GoodSize> list = goodSizeService.selectGoodSizeList(goodSize);
        ExcelUtil<GoodSize> util = new ExcelUtil<GoodSize>(GoodSize.class);
        util.exportExcel(response, list, "尺码管理数据");
    }

    /**
     * 获取尺码管理详细信息
     */
    @ApiOperation("获取尺码管理详细信息")
    @PreAuthorize("@ss.hasPermi('good:size:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(goodSizeService.selectGoodSizeById(id));
    }

    /**
     * 新增尺码管理
     */
    @ApiOperation("新增尺码管理")
    @PreAuthorize("@ss.hasPermi('good:size:add')")
    @Log(title = "尺码管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodSize goodSize) {
        return toAjax(goodSizeService.insertGoodSize(goodSize));
    }

    /**
     * 修改尺码管理
     */
    @ApiOperation("修改尺码管理")
    @PreAuthorize("@ss.hasPermi('good:size:edit')")
    @Log(title = "尺码管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodSize goodSize) {
        return toAjax(goodSizeService.updateGoodSize(goodSize));
    }

    /**
     * 删除尺码管理
     */
    @ApiOperation("删除尺码管理")
    @PreAuthorize("@ss.hasPermi('good:size:remove')")
    @Log(title = "尺码管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(goodSizeService.deleteGoodSizeByIds(ids));
    }
}
